﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

using FCNS.KeepMoney.Util;

namespace FCNS.KeepMoney.Configuration
{
    /// <summary>
    /// 主窗体配置类
    /// </summary>
    public sealed class AceMainForm
    {
        public AceMainForm()
        {
        }

        HotItemStyleEnum hotItem = HotItemStyleEnum.Border;
        public HotItemStyleEnum HotItemStyle
        {
            get { return hotItem; }
            set { hotItem = value; }
        }

        bool businessCardOverlay = true;
        /// <summary>
        /// 获取或设置是否显示记录统计窗体
        /// </summary>
        public bool BusinessCardOverlay
        {
            get { return businessCardOverlay; }
            set { businessCardOverlay = value; }
        }

        bool displayGroups = true;
        /// <summary>
        /// 获取或设置是否显示分组
        /// </summary>
        public bool DisplayGroups
        {
            get { return displayGroups; }
            set { displayGroups = value; }
        }

        int alternateRowBackColor = Color.FromKnownColor(KnownColor.Bisque).ToArgb();
        /// <summary>
        /// 账务记录背景颜色
        /// </summary>
        public int AlternateRowBackColor
        {
            get { return alternateRowBackColor; }
            set { alternateRowBackColor = value; }
        }

        bool gridLine = true;
        /// <summary>
        /// 获取或设置是否显示网格线
        /// </summary>
        public bool GridLine
        {
            get { return gridLine; }
            set { gridLine = value; }
        }

        bool showSubGroupEntry = true;
        /// <summary>
        /// 获取或设置是否显示子群组的记录
        /// </summary>
        public bool ShowSubGroupEntry
        {
            get { return showSubGroupEntry; }
            set { showSubGroupEntry = value; }
        }

        bool entryUseBackColor = true;
        public bool EntryUseBackColor
        {
            get { return entryUseBackColor; }
            set { entryUseBackColor = value; }
        }

        int leftPanel = 185;
        public int LeftPanelWidth
        {
            get
            {
                if (leftPanel < 50)
                    leftPanel = 185;

                return leftPanel;
            }
            set { leftPanel = value; }
        }

        UiType uiType = UiType.Money;
        public UiType UItype
        {
            get { return uiType; }
            set { uiType = value; }
        }

        bool showInTaskbar = false;
        /// <summary>
        /// 获取或设置最小化到系统托盘的同时也显示在任务栏
        /// </summary>
        public bool ShowInTaskBarAndTray
        {
            get { return showInTaskbar; }
            set { showInTaskbar = value; }
        }

        bool closeToTray = false;
        /// <summary>
        /// 获取或设置关闭程序时是否最小化到托盘
        /// </summary>
        public bool CloseToTray
        {
            get { return closeToTray; }
            set { closeToTray = value; }
        }

        bool miniToTray = false;
        /// <summary>
        /// 获取或设置是否最小化到托盘
        /// </summary>
        public bool MinimizeToTray
        {
            get { return miniToTray; }
            set { miniToTray = value; }
        }

        bool path = false;
        /// <summary>
        /// 获取或设置是否显示数据库路径
        /// </summary>
        public bool DisplaysTheFilePathInTheMainFormText
        {
            get { return path; }
            set
            {
                path = value;
            }
        }

        int chartHeight =300;
        /// <summary>
        /// 图表容器高度
        /// </summary>
        public int ChartHeight
        {
            get
            {
                if (chartHeight < 300)
                    chartHeight = 300;

                return chartHeight; }
            set { chartHeight = value; }
        }

        private int m_posX = AppDefines.InvalidWindowValue;
        /// <summary>
        /// 获取或设置 X 坐标
        /// </summary>
        public int X
        {
            get { return m_posX; }
            set { m_posX = value; }
        }

        private int m_posY = AppDefines.InvalidWindowValue;
        /// <summary>
        /// 获取或设置 Y 坐标
        /// </summary>
        public int Y
        {
            get { return m_posY; }
            set { m_posY = value; }
        }

        private int m_sizeW = AppDefines.InvalidWindowValue;
        /// <summary>
        /// 获取或设置宽度
        /// </summary>
        public int Width
        {
            get { return m_sizeW; }
            set { m_sizeW = value; }
        }

        private int m_sizeH = AppDefines.InvalidWindowValue;
        /// <summary>
        /// 获取或设置高度
        /// </summary>
        public int Height
        {
            get { return m_sizeH; }
            set { m_sizeH = value; }
        }

        private bool m_bMax = true;
        /// <summary>
        /// 获取或设置是否最大化
        /// </summary>
        [DefaultValue(false)]
        public bool Maximized
        {
            get { return m_bMax; }
            set { m_bMax = value; }
        }

        private string theme = "操作系统";
        /// <summary>
        /// 获取或设置横幅的显示主题
        /// </summary>
        public string FormTheme
        {
            get { return theme; }
            set { theme = value; }
        }

        private List<AceColumn> m_aceColumns = new List<AceColumn>();
        /// <summary>
        /// 获取或设置可显示的列
        /// </summary>
        [XmlArray("EntryListColumnCollection")]
        public List<AceColumn> ListViewEntryColumns
        {
            get { return m_aceColumns; }
            set
            {
                if (value == null) throw new ArgumentNullException("value");
                m_aceColumns = value;
            }
        }
 }


    /// <summary>
    /// 账务记录中的列类型
    /// </summary>
    public enum AceColumnType
    {
        Date = 0,
        Name,
        Money,
        Note,
        Tag,
        AlertDate,
        
       // Custom,

        Count //虚拟的，用于计算
    }

    /// <summary>
    /// 数据表格中的列配置类
    /// </summary>
    [XmlType(TypeName = "Column")]
    public sealed class AceColumn
    {
        int index = -1;
        /// <summary>
        /// 获取或设置列表控件中的索引
        /// </summary>
        public int ColumnIndex
        {
            get
            {
                if (index == -1)
                    return (int)m_type;
                else
                    return index;
            }
            set { index = value; }
        }
        bool sort = false;
        /// <summary>
        /// 获取或设置是否将此列用于排序
        /// </summary>
        public bool Sort
        {
            get { return sort; }
            set { sort = value; }
        }
        bool show = true;
        /// <summary>
        /// 获取或设置是否显示
        /// </summary>
        public bool Show
        {
            get { return show; }
            set { show = value; }
        }
        private AceColumnType m_type = AceColumnType.Count;
        /// <summary>
        /// 获取或设置列的类型
        /// </summary>
        public AceColumnType Type
        {
            get { return m_type; }
            set
            {
                if (((int)value >= 0) && ((int)value < (int)AceColumnType.Count))
                    m_type = value;
                else { }
            }
        }
        private string columnName = string.Empty;
        /// <summary>
        /// 获取或设置列名
        /// </summary>
        [DefaultValue("")]
        public string ColumnName
        {
            get { return columnName; }
            set
            {
                if (value == null) throw new ArgumentNullException("value");
                columnName = value;
            }
        }
        private int m_nWidth = -1;
        /// <summary>
        /// 获取或设置列宽
        /// </summary>
        public int Width
        {
            get
            {
                if (m_nWidth >= 0)
                    return m_nWidth;

                return 80;
            }
            set { m_nWidth = value; }
        }
        /// <summary>
        /// 构造函数(空)
        /// </summary>
        public AceColumn()
        {
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="t">列类型 <see cref="AceColumnType"/></param>
        /// <param name="strCustomName">自定义列名</param>
        /// <param name="nWidth">列宽</param>
        public AceColumn(AceColumnType t, string strCustomName, int nWidth)
        {
            m_type = t;
            columnName = strCustomName;
            m_nWidth = nWidth;
        }
        /// <summary>
        /// 获取列文本
        /// </summary>
        /// <returns></returns>
        public string GetDisplayName()
        {
            string str = string.Empty;

            switch (m_type)
            {
                case AceColumnType.Name: str = LanguageUtil.摘要; break;
                case AceColumnType.Note: str = LanguageUtil.备注; break;
                case AceColumnType.Money: str = LanguageUtil.金额; break;
                case AceColumnType.Date: str = LanguageUtil.日期; break;
                case AceColumnType.Tag: str = LanguageUtil.标记; break;
                case AceColumnType.AlertDate: str = LanguageUtil.提醒; break;
             //   case AceColumnType.Custom:str=
                default: Debug.Assert(false, "FCNS.KeepMoney.Configuration.AceColumn.GetDisplayName()"); break;
            };

            return str;
        }
        /// <summary>
        /// 获取文本的对齐方式
        /// </summary>
        /// <param name="t">列类型 <see cref="AceColumnType"/></param>
        /// <returns>如果列类型为'大小'或'记录合计'则返回 Right,否则为 Left.<see cref="HorizontalAlignment"/></returns>
        public static HorizontalAlignment GetTextAlign(AceColumnType t)
        {
            if (t == AceColumnType.Money)
                return HorizontalAlignment.Right;
            else
                return HorizontalAlignment.Left;
        }
    }
}
